package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbAddressMapper;
import com.dongdongshop.mapper.TbAreasMapper;
import com.dongdongshop.mapper.TbCitiesMapper;
import com.dongdongshop.mapper.TbProvincesMapper;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private TbAddressMapper tbAddressMapper;

    @Autowired
    private TbProvincesMapper tbProvincesMapper;

    @Autowired
    private TbCitiesMapper tbCitiesMapper;

    @Autowired
    private TbAreasMapper tbAreasMapper;

    @Override
    public List<TbAddress> getAddressInfo(String username) {
        List<TbAddress> list = tbAddressMapper.getAddressInfo(username);
        return list;
    }

    @Override
    public List<TbProvinces> getProvinceInfo() {
        return tbProvincesMapper.selectByExample(new TbProvincesExample());
    }

    @Override
    public void insertAddressInfo(TbAddress tbAddress) {
        tbAddressMapper.insertSelective(tbAddress);
    }

    @Override
    public List<TbCities> getCityInfo(String id) {
        if (id != "-1"){
            TbCitiesExample te = new TbCitiesExample();
            TbCitiesExample.Criteria criteria = te.createCriteria();
            criteria.andProvinceidEqualTo(id);
            return tbCitiesMapper.selectByExample(te);
        }
        return null;
    }

    @Override
    public List<TbAreas> getAreaInfo(String id) {
        if (id != "-1"){
            TbAreasExample te = new TbAreasExample();
            TbAreasExample.Criteria criteria = te.createCriteria();
            criteria.andCityidEqualTo(id);
            return tbAreasMapper.selectByExample(te);
        }
        return null;
    }
}
